package xyz.o0o0o.demo.ActiveMQDemo;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;

public class ReceiveMessage {

	public static void main(final String[] args) throws Exception {
		final ConnectionFactory connFactory = new ActiveMQConnectionFactory();

		final Connection conn = connFactory.createConnection();
		conn.start();  
		final Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

		final Destination dest = sess.createQueue("SampleQueue");

		final MessageConsumer consumer = sess.createConsumer(dest);

		Message message = consumer.receive(1000);
		
		if (message instanceof TextMessage) {
			TextMessage textMessage = (TextMessage) message;
			String text = textMessage.getText();
			System.out.println("11Received: " + text);
		} else {
			System.out.println("Received: " + message);
		}
		conn.close();
	}
}